<html>
<head>
  <title>[AccessFu] MathML Accessibility Support</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="output.js"></script>
  <script type="application/javascript"
          src="jsatcommon.js"></script>
  <script type="application/javascript">

    function doTest() {
      // Test the following accOrElmOrID.
      var tests = [{
          accOrElmOrID: "math-1",
          expectedUtterance: [
            [{"string":"open-fence"},"(","x",",","y",{"string":"close-fence"},")"],
            ["(",{"string":"open-fence"},"x",",","y",")",{"string":"close-fence"}]
          ],
          expectedBraille: [
            [{"string":"open-fenceAbbr"},"(","x",",","y",{"string":"close-fenceAbbr"},")"],
            ["(",{"string":"open-fenceAbbr"},"x",",","y",")",{"string":"close-fenceAbbr"}]
          ]
        }, {
          accOrElmOrID: "mfrac-1",
          expectedUtterance: [
            [{"string":"mathmlfraction"},{"string":"numerator"},"a",{"string":"denominator"},"b"],
            ["a",{"string":"numerator"},"b",{"string":"denominator"},{"string":"mathmlfraction"}]
          ],
          expectedBraille: [
            [{"string":"mathmlfractionAbbr"},{"string":"numeratorAbbr"},"a",{"string":"denominatorAbbr"},"b"],
            ["a",{"string":"numeratorAbbr"},"b",{"string":"denominatorAbbr"},{"string":"mathmlfractionAbbr"}]
          ]
        }, {
          accOrElmOrID: "mfrac-2",
          expectedUtterance: [
            [{"string":"mathmlfractionwithoutbar"},{"string":"numerator"},"a",{"string":"denominator"},"b"],
            ["a",{"string":"numerator"},"b",{"string":"denominator"},{"string":"mathmlfractionwithoutbar"}]
          ],
          expectedBraille: [
            [{"string":"mathmlfractionwithoutbarAbbr"},{"string":"numeratorAbbr"},"a",{"string":"denominatorAbbr"},"b"],
            ["a",{"string":"numeratorAbbr"},"b",{"string":"denominatorAbbr"},{"string":"mathmlfractionwithoutbarAbbr"}]
          ]
        }, {
          accOrElmOrID: "msub-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"subscript"},"b"],
            ["a",{"string":"base"},"b",{"string":"subscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"subscriptAbbr"},"b"],
            ["a",{"string":"baseAbbr"},"b",{"string":"subscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "msup-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"superscript"},"b"],
            ["a",{"string":"base"},"b",{"string":"superscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"superscriptAbbr"},"b"],
            ["a",{"string":"baseAbbr"},"b",{"string":"superscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "msubsup-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"subscript"},"b",{"string":"superscript"},"c"],
            ["a",{"string":"base"},"b",{"string":"subscript"},"c",{"string":"superscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"subscriptAbbr"},"b",{"string":"superscriptAbbr"},"c"],
            ["a",{"string":"baseAbbr"},"b",{"string":"subscriptAbbr"},"c",{"string":"superscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "mmultiscripts-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"subscript"},"b",{"string":"superscript"},"c",{"string":"superscript"},"d",{"string":"presubscript"},"e",{"string":"presubscript"},"f",{"string":"presuperscript"},"g"],
            ["a",{"string":"base"},"b",{"string":"subscript"},"c",{"string":"superscript"},"d",{"string":"superscript"},"e",{"string":"presubscript"},"f",{"string":"presubscript"},"g",{"string":"presuperscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"subscriptAbbr"},"b",{"string":"superscriptAbbr"},"c",{"string":"superscriptAbbr"},"d",{"string":"presubscriptAbbr"},"e",{"string":"presubscriptAbbr"},"f",{"string":"presuperscriptAbbr"},"g"],
            ["a",{"string":"baseAbbr"},"b",{"string":"subscriptAbbr"},"c",{"string":"superscriptAbbr"},"d",{"string":"superscriptAbbr"},"e",{"string":"presubscriptAbbr"},"f",{"string":"presubscriptAbbr"},"g",{"string":"presuperscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "munder-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"underscript"},"b"],
            ["a",{"string":"base"},"b",{"string":"underscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"underscriptAbbr"},"b"],
            ["a",{"string":"baseAbbr"},"b",{"string":"underscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "mover-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"overscript"},"b"],
            ["a",{"string":"base"},"b",{"string":"overscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"overscriptAbbr"},"b"],
            ["a",{"string":"baseAbbr"},"b",{"string":"overscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "munderover-1",
          expectedUtterance: [
            [{"string":"mathmlscripted"},{"string":"base"},"a",{"string":"underscript"},"b",{"string":"overscript"},"c"],
            ["a",{"string":"base"},"b",{"string":"underscript"},"c",{"string":"overscript"},{"string":"mathmlscripted"}]
          ],
          expectedBraille: [
            [{"string":"mathmlscriptedAbbr"},{"string":"baseAbbr"},"a",{"string":"underscriptAbbr"},"b",{"string":"overscriptAbbr"},"c"],
            ["a",{"string":"baseAbbr"},"b",{"string":"underscriptAbbr"},"c",{"string":"overscriptAbbr"},{"string":"mathmlscriptedAbbr"}]
          ]
        }, {
          accOrElmOrID: "mroot-1",
          expectedUtterance: [
            [{"string":"mathmlroot"},{"string":"base"},"a",{"string":"root-index"},"b"],
            ["a",{"string":"base"},"b",{"string":"root-index"},{"string":"mathmlroot"}]
          ],
          expectedBraille: [
            [{"string":"mathmlrootAbbr"},{"string":"baseAbbr"},"a",{"string":"root-indexAbbr"},"b"],
            ["a",{"string":"baseAbbr"},"b",{"string":"root-indexAbbr"},{"string":"mathmlrootAbbr"}]
          ]
        }, {
          accOrElmOrID: "mtable-1",
          expectedUtterance: [
            [{"string":"mathmltable"},{"string":"tblColumnInfo","count":3},{"string":"tblRowInfo","count":2},{"string":"columnInfo","args":[1]},{"string":"rowInfo","args":[1]},"a",{"string":"columnInfo","args":[2]},{"string":"rowInfo","args":[1]},"b",{"string":"columnInfo","args":[3]},{"string":"rowInfo","args":[1]},"c",{"string":"columnInfo","args":[1]},{"string":"rowInfo","args":[2]},"d",{"string":"columnInfo","args":[2]},{"string":"rowInfo","args":[2]},"e",{"string":"columnInfo","args":[3]},{"string":"rowInfo","args":[2]},"f"],
            ["a",{"string":"columnInfo","args":[1]},{"string":"rowInfo","args":[1]},"b",{"string":"columnInfo","args":[2]},{"string":"rowInfo","args":[1]},"c",{"string":"columnInfo","args":[3]},{"string":"rowInfo","args":[1]},"d",{"string":"columnInfo","args":[1]},{"string":"rowInfo","args":[2]},"e",{"string":"columnInfo","args":[2]},{"string":"rowInfo","args":[2]},"f",{"string":"columnInfo","args":[3]},{"string":"rowInfo","args":[2]},{"string":"mathmltable"},{"string":"tblColumnInfo","count":3},{"string":"tblRowInfo","count":2}]
          ],
          expectedBraille: [
            [{"string":"mathmltableAbbr"},{"string":"tblColumnInfoAbbr","count":3},{"string":"tblRowInfoAbbr","count":2},{"string":"cellInfoAbbr","args":[1,1]},"a",{"string":"cellInfoAbbr","args":[2,1]},"b",{"string":"cellInfoAbbr","args":[3,1]},"c",{"string":"cellInfoAbbr","args":[1,2]},"d",{"string":"cellInfoAbbr","args":[2,2]},"e",{"string":"cellInfoAbbr","args":[3,2]},"f"],
            ["a",{"string":"cellInfoAbbr","args":[1,1]},"b",{"string":"cellInfoAbbr","args":[2,1]},"c",{"string":"cellInfoAbbr","args":[3,1]},"d",{"string":"cellInfoAbbr","args":[1,2]},"e",{"string":"cellInfoAbbr","args":[2,2]},"f",{"string":"cellInfoAbbr","args":[3,2]},{"string":"mathmltableAbbr"},{"string":"tblColumnInfoAbbr","count":3},{"string":"tblRowInfoAbbr","count":2}]
          ]
      }, {
          accOrElmOrID: "menclose-1",
          expectedUtterance: [
            [{"string":"mathmlenclosed"},{"string":"notation-longdiv"},"a"],
            ["a",{"string":"notation-longdiv"},{"string":"mathmlenclosed"}]
          ],
          expectedBraille: [
            [{"string":"mathmlenclosedAbbr"},{"string":"notation-longdivAbbr"},"a"],
            ["a",{"string":"notation-longdivAbbr"},{"string":"mathmlenclosedAbbr"}]
          ]
        }, {
          accOrElmOrID: "menclose-2",
          expectedUtterance: [
            [{"string":"mathmlenclosed"},{"string":"notation-circle"},"a"],
            ["a",{"string":"notation-circle"},{"string":"mathmlenclosed"}]
          ],
          expectedBraille: [
            [{"string":"mathmlenclosedAbbr"},{"string":"notation-circleAbbr"},"a"],
            ["a",{"string":"notation-circleAbbr"},{"string":"mathmlenclosedAbbr"}]
          ]
        }, {
          accOrElmOrID: "menclose-3",
          expectedUtterance: [
            [{"string":"mathmlenclosed"},{"string":"notation-left"},{"string":"notation-top"},{"string":"notation-bottom"},"a"],
            ["a",{"string":"notation-left"},{"string":"notation-top"},{"string":"notation-bottom"},{"string":"mathmlenclosed"}]
          ],
          expectedBraille: [
            [{"string":"mathmlenclosedAbbr"},{"string":"notation-leftAbbr"},{"string":"notation-topAbbr"},{"string":"notation-bottomAbbr"},"a"],
            ["a",{"string":"notation-leftAbbr"},{"string":"notation-topAbbr"},{"string":"notation-bottomAbbr"},{"string":"mathmlenclosedAbbr"}]
          ]
        }];

      // Test all possible utterance order preference values.
      function testOutputOrder(aOutputOrder) {
        return function() {
          SpecialPowers.pushPrefEnv({
            "set": [[PREF_UTTERANCE_ORDER, aOutputOrder]]
          }, function() {
            tests.forEach(function run(test) {
              testOutput(test.expectedUtterance[aOutputOrder], test.accOrElmOrID,
                test.oldAccOrElmOrID, 1);
              testOutput(test.expectedBraille[aOutputOrder], test.accOrElmOrID,
                test.oldAccOrElmOrID, 0);
            });
            AccessFuTest.nextTest();
          });
        };
      }

      AccessFuTest.addFunc(testOutputOrder(0));
      AccessFuTest.addFunc(testOutputOrder(1));
      AccessFuTest.waitForExplicitFinish();
      AccessFuTest.runTests();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTest);
  </script>
</head>
<body>
  <div id="root">
    <a target="_blank"
       href="https://bugzilla.mozilla.org/show_bug.cgi?id=1163374"
       title="[AccessFu] MathML Accessibility Support">
      Mozilla Bug 1163374
    </a>
    <p id="display"></p>
    <div id="content" style="display: none"></div>
    <pre id="test"></pre>

    <math id="math-1"><mo>(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo>)</mo></math>

    <math>
      <mfrac id="mfrac-1">
        <mi>a</mi>
        <mi>b</mi>
      </mfrac>
    </math>

    <math>
      <mfrac id="mfrac-2" linethickness="0px">
        <mi>a</mi>
        <mi>b</mi>
      </mfrac>
    </math>

    <math>
      <msub id="msub-1">
        <mi>a</mi>
        <mi>b</mi>
      </msub>
    </math>
    <math>
      <msup id="msup-1">
        <mi>a</mi>
        <mi>b</mi>
      </msup>
    </math>
    <math>
      <msubsup id="msubsup-1">
        <mi>a</mi>
        <mi>b</mi>
        <mi>c</mi>
      </msubsup>
    </math>
    <math>
      <mmultiscripts id="mmultiscripts-1">
        <mi>a</mi>
        <mi>b</mi>
        <mi>c</mi>
        <none/>
        <mi>d</mi>
        <mprescripts/>
        <mi>e</mi>
        <none/>
        <mi>f</mi>
        <mi>g</mi>
      </mmultiscripts>
    </math>

    <math>
      <munder id="munder-1">
        <mi>a</mi>
        <mi>b</mi>
      </munder>
    </math>
    <math>
      <mover id="mover-1">
        <mi>a</mi>
        <mi>b</mi>
      </mover>
    </math>
    <math>
      <munderover id="munderover-1">
        <mi>a</mi>
        <mi>b</mi>
        <mi>c</mi>
      </munderover>
    </math>

    <math>
      <mroot id="mroot-1">
        <mi>a</mi>
        <mi>b</mi>
      </mroot>
    </math>

    <math>
      <mtable id="mtable-1">
        <mtr>
          <mtd><mi>a</mi></mtd>
          <mtd><mi>b</mi></mtd>
          <mtd><mi>c</mi></mtd>
        </mtr>
        <mtr>
          <mtd><mi>d</mi></mtd>
          <mtd><mi>e</mi></mtd>
          <mtd><mi>f</mi></mtd>
        </mtr>
      </mtable>
    </math>

    <math>
      <menclose id="menclose-1"><mi>a</mi></menclose>
    </math>
    <math>
      <menclose id="menclose-2" notation="circle"><mi>a</mi></menclose>
    </math>
    <math>
      <menclose id="menclose-3" notation="left top bottom"><mi>a</mi></menclose>
    </math>

  </div>
</body>
</html>
